package org.jivesoftware.smackx;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;
import org.jivesoftware.smackx.packet.OfflineMessageInfo;
import org.jivesoftware.smackx.packet.OfflineMessageRequest;
import org.jivesoftware.smackx.packet.OfflineMessageRequest.Item;

public class OfflineMessageManager
{
  private static final String namespace = "http://jabber.org/protocol/offline";
  private Connection connection;
  private PacketFilter packetFilter;

  public OfflineMessageManager(Connection paramConnection)
  {
    this.connection = paramConnection;
    this.packetFilter = new AndFilter(new PacketFilter[] { new PacketExtensionFilter("offline", "http://jabber.org/protocol/offline"), new PacketTypeFilter(Message.class) });
  }

  public boolean supportsFlexibleRetrieval()
    throws XMPPException
  {
    DiscoverInfo localDiscoverInfo = ServiceDiscoveryManager.getInstanceFor(this.connection).discoverInfo(this.connection.getServiceName());
    return localDiscoverInfo.containsFeature("http://jabber.org/protocol/offline");
  }

  public int getMessageCount()
    throws XMPPException
  {
    DiscoverInfo localDiscoverInfo = ServiceDiscoveryManager.getInstanceFor(this.connection).discoverInfo(null, "http://jabber.org/protocol/offline");
    Form localForm = Form.getFormFrom(localDiscoverInfo);
    if (localForm != null)
    {
      String str = (String)localForm.getField("number_of_messages").getValues().next();
      return Integer.parseInt(str);
    }
    return 0;
  }

  public Iterator<OfflineMessageHeader> getHeaders()
    throws XMPPException
  {
    ArrayList localArrayList = new ArrayList();
    DiscoverItems localDiscoverItems = ServiceDiscoveryManager.getInstanceFor(this.connection).discoverItems(null, "http://jabber.org/protocol/offline");
    Iterator localIterator = localDiscoverItems.getItems();
    while (localIterator.hasNext())
    {
      DiscoverItems.Item localItem = (DiscoverItems.Item)localIterator.next();
      localArrayList.add(new OfflineMessageHeader(localItem));
    }
    return localArrayList.iterator();
  }

  public Iterator<Message> getMessages(final List<String> paramList)
    throws XMPPException
  {
    ArrayList localArrayList = new ArrayList();
    OfflineMessageRequest localOfflineMessageRequest = new OfflineMessageRequest();
    Object localObject2 = paramList.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (String)((Iterator)localObject2).next();
      localObject3 = new OfflineMessageRequest.Item((String)localObject1);
      ((OfflineMessageRequest.Item)localObject3).setAction("view");
      localOfflineMessageRequest.addItem((OfflineMessageRequest.Item)localObject3);
    }
    Object localObject1 = new PacketIDFilter(localOfflineMessageRequest.getPacketID());
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    Object localObject3 = new AndFilter(new PacketFilter[] { this.packetFilter, new PacketFilter()
    {
      public boolean accept(Packet paramAnonymousPacket)
      {
        OfflineMessageInfo localOfflineMessageInfo = (OfflineMessageInfo)paramAnonymousPacket.getExtension("offline", "http://jabber.org/protocol/offline");
        return paramList.contains(localOfflineMessageInfo.getNode());
      }
    }
     });
    PacketCollector localPacketCollector = this.connection.createPacketCollector((PacketFilter)localObject3);
    this.connection.sendPacket(localOfflineMessageRequest);
    IQ localIQ = (IQ)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
    for (Message localMessage = (Message)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout()); localMessage != null; localMessage = (Message)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout()))
      localArrayList.add(localMessage);
    localPacketCollector.cancel();
    return localArrayList.iterator();
  }

  public Iterator<Message> getMessages()
    throws XMPPException
  {
    ArrayList localArrayList = new ArrayList();
    OfflineMessageRequest localOfflineMessageRequest = new OfflineMessageRequest();
    localOfflineMessageRequest.setFetch(true);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localOfflineMessageRequest.getPacketID());
    PacketCollector localPacketCollector1 = this.connection.createPacketCollector(localPacketIDFilter);
    PacketCollector localPacketCollector2 = this.connection.createPacketCollector(this.packetFilter);
    this.connection.sendPacket(localOfflineMessageRequest);
    IQ localIQ = (IQ)localPacketCollector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector1.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
    for (Message localMessage = (Message)localPacketCollector2.nextResult(SmackConfiguration.getPacketReplyTimeout()); localMessage != null; localMessage = (Message)localPacketCollector2.nextResult(SmackConfiguration.getPacketReplyTimeout()))
      localArrayList.add(localMessage);
    localPacketCollector2.cancel();
    return localArrayList.iterator();
  }

  public void deleteMessages(List<String> paramList)
    throws XMPPException
  {
    OfflineMessageRequest localOfflineMessageRequest = new OfflineMessageRequest();
    Object localObject2 = paramList.iterator();
    while (((Iterator)localObject2).hasNext())
    {
      localObject1 = (String)((Iterator)localObject2).next();
      localObject3 = new OfflineMessageRequest.Item((String)localObject1);
      ((OfflineMessageRequest.Item)localObject3).setAction("remove");
      localOfflineMessageRequest.addItem((OfflineMessageRequest.Item)localObject3);
    }
    Object localObject1 = new PacketIDFilter(localOfflineMessageRequest.getPacketID());
    localObject2 = this.connection.createPacketCollector((PacketFilter)localObject1);
    this.connection.sendPacket(localOfflineMessageRequest);
    Object localObject3 = (IQ)((PacketCollector)localObject2).nextResult(SmackConfiguration.getPacketReplyTimeout());
    ((PacketCollector)localObject2).cancel();
    if (localObject3 == null)
      throw new XMPPException("No response from server.");
    if (((IQ)localObject3).getError() != null)
      throw new XMPPException(((IQ)localObject3).getError());
  }

  public void deleteMessages()
    throws XMPPException
  {
    OfflineMessageRequest localOfflineMessageRequest = new OfflineMessageRequest();
    localOfflineMessageRequest.setPurge(true);
    PacketIDFilter localPacketIDFilter = new PacketIDFilter(localOfflineMessageRequest.getPacketID());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localPacketIDFilter);
    this.connection.sendPacket(localOfflineMessageRequest);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smackx.OfflineMessageManager
 * JD-Core Version:    0.6.1
 */